api = {
	/*
	 * NOTE: You must get your own API key from
	 * http://code.google.com/apis/moderator/v1/getting_started.html#prereqs-getkey
	 * in order to be able to run this app 	 
	 */
	KEY : '[PASTE YOUR API KEY HERE]',
	ID : 0x4dd4d,
	URL : 'https://www.googleapis.com/moderator/v1/series/',
	handler : function(e, success, failure){
		if (this.readyState == 4) {
			if (this.status == 200) {
				// Replace single quotes
				var response = this.responseText.replace(/'/g, '&rsquo;');
				success(eval('(' + response + ')').data);
				delete this;
			}
			else {
				failure(this);
				delete this;
			}
		}
	},
	get : function(url, success, failure){
		var xhr = new XMLHttpRequest();
		xhr.open('GET', url);
		xhr.onreadystatechange = function(e){
			api.handler.call(this, e, success, failure);
		};
		xhr.send(null);
	},
	series : {
		get : function(success, failure){
			api.get.call(this, api.URL + api.ID + '?key=' + api.KEY,
				success, failure);
		}
	},
	topics : {
		list : function(success, failure){
			api.get.call(this, api.URL + api.ID + '/topics?key=' + api.KEY,
				success, failure);
		},
		get : function(id, success, failure){
			api.get.call(this, api.URL + api.ID + '/topics/' + id  + '?key=' + api.KEY,
				success, failure);
		}
	},
	submissions : {
		list : function(id, success, failure){
			if(id instanceof Function) {
				success = arguments[0];
				failure = arguments[1];
				id = null;
			}
			if(id){
				api.get.call(this, api.URL + api.ID + '/topics/' + id  + '/submissions?key=' + api.KEY,
					success, failure);
			}else{
				api.get.call(this, api.URL + api.ID + '/submissions?key=' + api.KEY,
					success, failure);
			}
		},
		get : function(id, success, failure){/* Not yet implemented */},
		insert : function(id, success, failure){/* Not yet implemented */}
	},
	votes : {
		list : function(){/* Not yet implemented */},
		get : function(){/* Not yet implemented */},
		insert : function(){/* Not yet implemented */},
		update : function(){/* Not yet implemented */}
	}
}